package com.example.reids;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@SpringBootApplication
@Controller
public class ReidsApplication {
	@Autowired
    private RedisService service;

    public static void main(String[] args) {
        SpringApplication.run(ReidsApplication.class, args);
    }

    @GetMapping("/")
    @ResponseBody
    public String hello(@RequestParam("num") Integer num) {
        String result = "";
        for(int i=0;i<num;i++) {
            Student student = service.getStudent("" + i);
            result += student.toString()+"\n";
        }
        return result;
    }

    @GetMapping("/set")
    @ResponseBody
    public Integer set(@RequestParam("num") Integer num){
        if (num==0){
            num=1;
        }
        for (int i=0;i<num;i++){
            Thread thread = new Thread(new RunTest(service,i));
            thread.start();
        }
        return num;
    }
}

